{% include 'admin/header.html' %}

<body>
  <div class="lyear-layout-web">
    <div class="lyear-layout-container">
      {% include 'admin/nav.html' %}

      <main class="lyear-layout-content">
        <div class="container-fluid">
          <!-- 提示信息 -->
          <div class="alert alert-info alert-dismissible fade show mb-4" role="alert">
            <i class="fas fa-info-circle mr-2"></i>
            请确保宿舍信息完整，缺失或错误信息可能导致系统无法正常运行。

          </div>

          <!-- 卡片标题部分 -->
          <div class="card shadow-lg mb-4">
            <header class="card-header d-flex justify-content-between align-items-center">
              <h4 class="card-title mb-0 text-primary">宿舍管理</h4>
              <div>
                <a href="{{ url_for('main.add_dorm') }}" class="btn btn-primary btn-sm">添加宿舍</a>
              </div>
            </header>

            <!-- 卡片内容部分 -->
            <div class="card-body">
              <div class="table-responsive">
                <table class="table table-bordered table-striped table-hover">
                  <thead class="thead-light">
                    <tr>
                      <th>#</th>
                      <th>宿舍编号</th>
                      <th>宿舍名称</th>
                      <th>宿舍类型</th>
                      <th>床位数</th>
                      <th>已占床位</th>
                      <th>剩余床位</th>
                      <th>操作</th>
                    </tr>
                  </thead>
                  <tbody>
                    {% for dorm in dorms %}
                    <tr>
                      <td>{{ loop.index }}</td>
                      <td>{{ dorm.id }}</td>
                      <td>{{ dorm.name }}</td>
                      <td>{{ dorm.dorm_typeid }}</td>
                      <td>{{ dorm.bed_count }}</td>
                      <td>{{ dorm.occupied }}</td>
                      <td>{{ dorm.remaining_beds }}</td>
                      <td class="text-center">
                        <a href="{{ url_for('main.edit_dorm', id=dorm.id) }}" class="btn btn-warning btn-sm mr-2">编辑</a>
                        <form action="{{ url_for('main.delete_dorm', id=dorm.id) }}" method="POST" style="display:inline;">
                          <button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('确定删除该宿舍吗？')">删除</button>
                        </form>
                      </td>
                    </tr>
                    {% endfor %}
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
      </main>
    </div>
  </div>

{% include 'admin/footer.html' %}
</body>
